package servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.Enumeration;

@WebServlet(name = "ContextServlet", value = "/context")
public class Demo8_ContextServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //获取servlet上下文
        ServletContext context = request.getServletContext();

        context.setAttribute("season","summer");
        context.setAttribute("year","2033");

        System.out.println(context.getAttribute("season"));

        context.removeAttribute("season");


        Enumeration<String> attributeNames = context.getAttributeNames();
        while (attributeNames.hasMoreElements()){
            System.out.println(attributeNames.nextElement());
        }


        System.out.println(context.getContextPath());

        System.out.println(context.getRealPath("/context"));

        System.out.println(context.getResourcePaths("/"));

    }
}
